library(igraph)
library(here)
load edgelist
# Step 1: Read the edge list from the .txt file
file_path <- here("lecture-2/collaboration.edgelist.txt")
edge_list <- read.table(file_path, sep = "\t", header = FALSE)
#convert to an igraph network
matrix1 <- as.matrix(edge_list) #igraph wants our data in matrix format
head(matrix)
##
## 1 function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)
## 2 {
## 3 if (is.object(data) || !is.atomic(data))
## 4 data <- as.vector(data)
## 5 .Internal(matrix(data, nrow, ncol, byrow, dimnames, missing(nrow),
## 6 missing(ncol)))
class(matrix1)
## [1] "matrix" "array"
- note, there are 0s which will result in an error when we using the graph_from_edgelist function. we can solve this by adding all of the items in the edgelist by 1
Attempt at ploting a graph
# Step 2: Adjust vertex IDs to start from 1
adjusted_edge_list <- as.matrix(edge_list + 1)
net1 <- graph.edgelist(adjusted_edge_list, directed=FALSE)
library(RBioFabric)
bioFabric(net1)
## Warning in graph.bfs(bfGraphPass1, startIndex, neimode = "all"): Argument
## `neimode' is deprecated; use `mode' instead
